#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'teffy'

'''
@filename main
@@created on 2017-12-16
@poject:work-kit
@auther:teffy
'''

import PyQt5.uic,sys,os
from PyQt5.QtWidgets import QApplication, QMainWindow

main_window_ui_file = 'main_window.ui'
add_command_ui_file = 'add_command_dialog.ui'

(Ui_MainWindow, QtBaseClass) = PyQt5.uic.loadUiType(main_window_ui_file)
(Ui_Dialog, QtDialogBaseClass) = PyQt5.uic.loadUiType(add_command_ui_file)

class MAddCommandDialog(QMainWindow, Ui_Dialog):
    def __init__(self):
        QMainWindow.__init__(self)
        Ui_Dialog.__init__(self)
        self.setupUi(self)
        self.setWindowTitle('添加命令')
        self.move(100, 100)
        self.save_command_btn.clicked.connect(self.saveCommand)
        self.test_command_btn.clicked.connect(self.testCommand)

    def testCommand(self):
        print('test')

    def saveCommand(self):
        print('save')


class MWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.move(100, 100)
        self.setWindowTitle('Welcome')
        self.add_command_btn.clicked.connect(self.addCommand)

    def addCommand(self):
        print('1')
        # addDialog.show()
        import subprocess

        result = subprocess.run(['ping', 'www.baidu.com'], stdout=subprocess.PIPE)
        print(result.stdout.decode('utf-8'))

        '''
        command = 'ping www.baidu.com'
        r = os.popen(command)
        info = r.readlines()
        for line in info:
            line = line.strip('\r\n')
            print(line)
        '''


if __name__ == '__main__':
    app = QApplication(sys.argv)
    addDialog = MAddCommandDialog()
    main_window = MWindow()
    main_window.show()
    print(dir(main_window))
    sys.exit(app.exec_())
